
class Vector {
  constructor(x, y){
    this.x = x
    this.y = y
  }

  Set(x, y) {
    if (x instanceof Vector) {
      this.x = x.x
      this.y = x.y
    } else {
      this.x = x
      this.y = y
    }
  }

  Add(vec) {
    this.x += vec.x
    this.y += vec.y
    return this
  }

  Sub(vec) {
    this.x -= vec.x
    this.y -= vec.y
    return this
  }

  Scale(scale) {
    this.x *= scale
    this.y *= scale
    return this
  }

  Dot(vec) {
    return this.x * vec.x + this.y * vec.y
  }

  Copy() {
    return new Vector(this.x, this.y)
  }

  Size() {
    return Math.sqrt(this.x * this.x + this.y * this.y)
  }

  IsZero() {
    return this.x == 0 && this.y == 0
  }
}

module.exports = {
  Vector
}